/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software Foundation,
 *    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

package JET.VirtualKeyboard;

import JET.Actions.Action;
import java.util.ArrayList;

/**
 *
 * @author 057Ry
 */
public class VKey
{
    ArrayList<Action> pressActions;
    ArrayList<Action> releaseActions;
    private String name;

    /** Indicates if key is pressed down or not. */
    private boolean pressed;

    /** Is meant to store moment in simulation time when key was pressed.
     *  This is essential for press time calculation. */
    private double pressReleaseMoment;

    /* Code of key, values for avaiable keys are stored in Java native class
     * KeyEvent.VK_<key name> static fields. */
    private int keyCode;

    public VKey(int keyCode, String name)
    {
        this.name = name;
        this.keyCode = keyCode;
        pressActions = new ArrayList<Action>();
        releaseActions = new ArrayList<Action>();
    }

    public void setPressed(boolean p) {
        this.pressed = p;
    }
    public boolean isPressed() {
        return this.pressed;
    }

    public void setPressReleaseMoment(double t) {
        this.pressReleaseMoment = t;
    }
    public double getPressReleaseMoment() {
        return this.pressReleaseMoment;
    }

    public ArrayList<Action> getPressActions()
    {
        return pressActions;
    }

    public ArrayList<Action> getReleaseActions()
    {
        return releaseActions;
    }

    public void callPressActions()
    {
        for(Action a : pressActions)
            a.call();
    }

    public void callReleaseActions()
    {
        for(Action a : releaseActions)
            a.call();
    }

    public int getCode()
    {
        return keyCode;
    }

    @Override
    public String toString()
    {
        return name;
    }
}
